package com.apiz.service.impl.inner;

import com.apiz.common.model.entity.UserInterfaceInfo;
import com.apiz.common.service.InnerUserInterfaceInfoService;
import com.apiz.mapper.UserInterfaceInfoMapper;
import com.apiz.service.UserInterfaceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class InnerUserInterfaceInfoServiceImpl implements InnerUserInterfaceInfoService {

    @Resource
    UserInterfaceInfoService userInterfaceInfoService;

    @Resource
    UserInterfaceInfoMapper userInterfaceInfoMapper;

    @Override
    public boolean invokeCount(long interfaceInfoId, long userId) {
       return userInterfaceInfoService.invokeCount(userId,interfaceInfoId);
    }

    /**
     * 查看 是否有調用資格 1.是否分配給用戶接口 是否有調用次數
     * @param interfaceInfoId
     * @param userId
     * @return
     */
    @Override
    public boolean invokeCondition(long interfaceInfoId, long userId) {

        //1 判斷用戶是否分配接口
        //2 是否還有調用次數
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("userId",userId);
        queryWrapper.eq("interfaceInfoId",interfaceInfoId);
        queryWrapper.gt("leftNum",0);

        UserInterfaceInfo userInterfaceInfo = userInterfaceInfoMapper.selectOne(queryWrapper);


        return userInterfaceInfo == null ? false : true;
    }
}
